package org.jeecg.common.util;

import cn.hutool.core.util.ObjectUtil;
import org.apache.commons.lang.StringUtils;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class IOFileUtil {

    public static int genTxtFile(String genFilePath, List<String> fileContent) {
        if (StringUtils.isEmpty(genFilePath)) {
            return 0;
        }
        if (ObjectUtil.isEmpty(fileContent)) {
            return 0;
        }
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(genFilePath))) {
            // 遍历List并写入到文件中
            for (String item : fileContent) {
                writer.write(item);
                writer.newLine();  // 添加新行
            }
            System.out.println("List content has been written to " + genFilePath);
        } catch (IOException e) {
            e.printStackTrace();
            return 0;
        }
        return 1;
    }
}
